﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPIDesktopClient.Entities;
using System.Data;
using PPIDesktopClient.General;
using PPIProxy;
using VMind.Global;
using PPIMobileInterface;

namespace PPIDesktopClient.Logic
{
    public class LVendor_Visit_Type
    {
        public static List<EVendor_Visit_Type> SelectAllIdName(DataTable dt)
        {
            List<EVendor_Visit_Type> _Vendor_Visit_TypeList = new List<EVendor_Visit_Type>();
            EVendor_Visit_Type _Vendor_Visit_Type;

            foreach (DataRow dr in dt.Rows)
            {
                _Vendor_Visit_Type = new EVendor_Visit_Type(ConvertHelper.ToInt32(dr["Vendor_Visit_TypeID"]), dr["Name"].ToString());
                _Vendor_Visit_TypeList.Add(_Vendor_Visit_Type);
            }
            return _Vendor_Visit_TypeList;
        }
        public static List<EVendor_Visit_Type> SelectAllIdName()
        {
            ConfigReader _Reader = ConfigReader.GetInstance();
            DataTable dt = WVendor_Visit_Type.SelectAllIdName(_Reader.GetConnectionString()).Tables[0];
            return SelectAllIdName(dt);
        }

        public static void InsertVisitType(string connectionString)
        {

            StringBuilder _query = new StringBuilder();
            List<EVendor_Visit_Type> _visits = LVendor_Visit_Type.SelectAllIdName();
            foreach (EVendor_Visit_Type v in _visits)
            {
                _query.AppendLine("insert into tb_Lookups (LookupValue,LookupText,LookupTypeFk) values (" + v.Vendor_Visit_TypeId + ",'" + v.Name + "','VisitTypes')");
            }
            Utils.InsertVisitType(connectionString, _query.ToString());
        }
    }
}
